home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / checkbox / traverser.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  8.1 KB  |  157 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. The traverser exposes a simple iterator interface for accessing the graph
  6. of tests as expressed by the dependency tree. The constructor provides an
  7. additional callbacks instance for processing tests which might be skipped.
  8. '''
  9. import logging
  10. from checkbox.lib.iterator import Iterator, IteratorContain, IteratorExclude, IteratorPostRepeat, IteratorPreRepeat
  11. from checkbox.resolver import Resolver
  12. from checkbox.test import FAIL, SKIP
  13.  
  14. class TraverserCallbacks(object):
  15.     
  16.     def get_architecture(self):
  17.         pass
  18.  
  19.     
  20.     def get_category(self):
  21.         pass
  22.  
  23.     
  24.     def get_priorities(self):
  25.         return []
  26.  
  27.     
  28.     def skipped_dependent(self, test, result):
  29.         logging.info("Test '%s' dependent on skipped test", test.name)
  30.  
  31.     
  32.     def failed_dependent(self, test, result):
  33.         logging.info("Test '%s' dependent on failed test", test.name)
  34.  
  35.     
  36.     def unsupported_requires(self, test, result):
  37.         logging.info("Test '%s' does not support requires field: %s", test.name, test.requires)
  38.  
  39.     
  40.     def undefined_architecture(self, test, result):
  41.         logging.info('No system architecture defined, skipping test: %s', test.name)
  42.  
  43.     
  44.     def unsupported_architecture(self, test, result):
  45.         logging.info('System architecture not supported, skipping test: %s', test.name)
  46.  
  47.     
  48.     def undefined_category(self, test, result):
  49.         logging.info('No system category defined, skipping test: %s', test.name)
  50.  
  51.     
  52.     def unsupported_category(self, test, result):
  53.         logging.info('System category not supported, skipping test: %s', test.name)
  54.  
  55.  
  56.  
  57. class Traverser(IteratorContain):
  58.     
  59.     def __init__(self, tests = [], callbacks = TraverserCallbacks, *args, **kwargs):
  60.         self._callbacks = callbacks(*args, **kwargs)
  61.         self._dependent_next = []
  62.         self._dependent_prev = []
  63.         self._dependent_status = None
  64.         resolver = Resolver(self._compare_func)
  65.         test_dict = dict((lambda .0: for t in .0:
  66. ((t.suite, t.name), t))(tests))
  67.         for test in tests:
  68.             test_depends = [ test_dict[(test.suite, d)] for d in test.depends ]
  69.             resolver.add(test, *test_depends)
  70.         
  71.         tests = resolver.get_dependents()
  72.         iterator = Iterator(tests)
  73.         iterator = IteratorExclude(iterator, self._requires_exclude_func, self._requires_exclude_func)
  74.         iterator = IteratorExclude(iterator, self._architecture_exclude_func, self._architecture_exclude_func)
  75.         iterator = IteratorExclude(iterator, self._category_exclude_func, self._category_exclude_func)
  76.         iterator = IteratorExclude(iterator, self._dependent_exclude_next_func, self._dependent_exclude_prev_func)
  77.         iterator = IteratorPreRepeat(iterator, (lambda test, result, resolver = (resolver,): self._dependent_prerepeat_next_func(test, result, resolver)))
  78.         iterator = IteratorPostRepeat(iterator, prev_func = (lambda test, result, resolver = (resolver,): self._dependent_prerepeat_prev_func(test, result, resolver)))
  79.         super(Traverser, self).__init__(iterator)
  80.  
  81.     
  82.     def _compare_func(self, a, b):
  83.         priorities = self._callbacks.get_priorities()
  84.         if a.plugin in priorities:
  85.             if b.plugin in priorities:
  86.                 ia = priorities.index(a.plugin)
  87.                 ib = priorities.index(b.plugin)
  88.                 if ia != ib:
  89.                     return cmp(ia, ib)
  90.             else:
  91.                 return -1
  92.         b.plugin in priorities
  93.         if b.plugin in priorities:
  94.             return 1
  95.         return cmp((a.suite, a.name), (b.suite, b.name))
  96.  
  97.     
  98.     def _dependent_prerepeat_next_func(self, test, result, resolver):
  99.         '''IteratorPreRepeat function which completely skips dependents
  100.            of tests which either have a status of FAIL or SKIP.'''
  101.         if result and result.test == test:
  102.             if result.status == FAIL or result.status == SKIP:
  103.                 self._dependent_next = resolver.get_dependents(test)
  104.                 self._dependent_status = result.status
  105.             else:
  106.                 self._dependent_next = []
  107.         
  108.         self._dependent_prev.append(test)
  109.  
  110.     
  111.     def _dependent_prerepeat_prev_func(self, test, result, resolver):
  112.         '''IteratorPreRepeat function which supplements the above by
  113.            keeping track of a stack of previously run tests.'''
  114.         self._dependent_prev.pop()
  115.  
  116.     
  117.     def _dependent_exclude_next_func(self, test, result):
  118.         if test in self._dependent_next:
  119.             if self._dependent_status == FAIL:
  120.                 self._callbacks.failed_dependent(test, result)
  121.             elif self._dependent_status == SKIP:
  122.                 self._callbacks.skipped_dependent(test, result)
  123.             
  124.             return True
  125.         return False
  126.  
  127.     
  128.     def _dependent_exclude_prev_func(self, test, result):
  129.         if self._dependent_prev[-1] != test:
  130.             return True
  131.         return False
  132.  
  133.     
  134.     def _requires_exclude_func(self, test, result):
  135.         '''IteratorExclude function which removes test when the
  136.            requires field contains a False value.'''
  137.         if False in test.requires.get_mask():
  138.             self._callbacks.unsupported_requires(test, result)
  139.             return True
  140.         return False
  141.  
  142.     
  143.     def _architecture_exclude_func(self, test, result):
  144.         """IteratorExclude function which removes test when the
  145.            architectures field exists and doesn't meet the given
  146.            requirements."""
  147.         return False
  148.  
  149.     
  150.     def _category_exclude_func(self, test, result):
  151.         """IteratorExclude function which removes test when
  152.            the categories field exists and doesn't meet the given
  153.            requirements."""
  154.         return False
  155.  
  156.  
  157.